package com.el.thread;

public class TraditionaThreadSynchronized {
    public static void main(String[] args){
            new TraditionaThreadSynchronized().init();
    }
    private void init(){
        final Outputer outputer=new Outputer();
        new Thread(new Runnable() {
            public void run() {
                while(true){
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    outputer.output("zhangxiaoxiang");
                }
            }
        }).start();
        new Thread(new Runnable() {
            public void run() {
                while(true){
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    outputer.output1("lihuoming");
                }
            }
        }).start();
        System.out.println("");
    }
   static class Outputer{
        String  str="";
        public synchronized void output(String name) {
            int len = name.length();
            synchronized (Outputer.class) {
                for (int i = 0; i < len; i++) {
                    System.out.print(name.charAt(i));
                }
                System.out.println();
            }
        }

        public static synchronized void output1(String name) {
            int len = name.length();
            //synchronized (this) {
            for (int i = 0; i < len; i++) {
                System.out.print(name.charAt(i));
            }
            System.out.println();
        }
    }
}
